from . import Base
from sqlalchemy import Column, VARCHAR, Integer, ForeignKey, TEXT


class Snak(Base):
    __tablename__ = "snak"
    id = Column(Integer, primary_key=True)
    pid = Column(VARCHAR(10))  # property id
    snaktype = Column(VARCHAR(10))
    datatype = Column(VARCHAR(20))
    datavalue = Column(TEXT)

    ID = 0

    @classmethod
    def get_id(cls):
        cls.ID += 1
        return cls.ID


class Statement(Base):
    __tablename__ = "statement"
    id = Column(VARCHAR(50), primary_key=True)
    eid = Column(VARCHAR(10), ForeignKey("entity.id"))
    type = Column(VARCHAR(10))
    msid = Column(Integer, ForeignKey("snak.id"))
    rank = Column(VARCHAR(50))


class Qualifier(Base):
    __tablename__ = "qualifier"
    id = Column(Integer, primary_key=True)
    sid = Column(VARCHAR(50), ForeignKey("statement.id"))
    pid = Column(VARCHAR(10))  # property id
    hash = Column(VARCHAR(50))
    snaktype = Column(VARCHAR(20))
    datatype = Column(VARCHAR(20))
    datavalue = Column(TEXT)


class Reference(Base):
    __tablename__ = "reference"
    id = Column(Integer, primary_key=True)
    sid = Column(VARCHAR(50), ForeignKey("statement.id"))
    hash = Column(VARCHAR(50))
    snakorder = Column(TEXT)

    ID = 0

    @classmethod
    def get_id(cls):
        cls.ID += 1
        return cls.ID


class SR(Base):
    __tablename__ = "sr"
    rid = Column(Integer, ForeignKey("reference.id"), primary_key=True)
    skid = Column(Integer, ForeignKey("snak.id"), primary_key=True)
